<template>
	<view>
		<uni-nav-bar @clickLeft="$tab.back()" fixed="true" left-icon="left" title="我的置换" statusBar="true"
			:border="false" />

		<view class="bg-FFF">
			<u-tabs :scrollable="false" :list="tabsList" lineWidth="30" lineColor="#FA554E" :activeStyle="{
		            color: '#FA554E',
		            fontWeight: 'bold',
		            transform: 'scale(1.05)'
		        }" :inactiveStyle="{
		            color: '#606266',
		            transform: 'scale(1)'
		        }" @change="tabChange">
			</u-tabs>
		</view>

		<view class="px-20">
			<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :fixed="false">
				<view class="bg-FFF p-16 mt-28" v-for="(item,index) in list" :key="item.id">
					<view class="flex items-center justify-between">
						<view class="">
							{{item.createTime}}
						</view>
						<view class="text-FF7C01">
							{{item.verifyState==0?'审核中':item.verifyState==1?'已同意':item.verifyState==2?'已拒绝':''}}
						</view>
					</view>
					<u-divider></u-divider>
					<view class="">
						名称:{{item.profile}}
					</view>
					<view class="mt-12" v-if="item.amount">
						评估价格:{{item.amount+item.moneyName}}
					</view>
				</view>
			</s-pull-scroll>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsList: [{
						name: '审核中'
					},
					{
						name: '已同意'
					},
					{
						name: '已拒绝'
					}
				],
				tabsIndex: 0,
				list: []
			};
		},
		onLoad() {
			this.refresh()
		},
		methods: {
			tabChange(e) {
				console.log(e)
				this.tabsIndex = e.index
				this.refresh()
			},
			refresh() {
				this.$nextTick(() => {
					this.$refs.pullScroll.refresh();
				});
			},
			pullDown(pullScroll) {
				setTimeout(() => {
					this.loadData(pullScroll);
				}, 200);
			},
			loadData(pullScroll) {
				setTimeout(async () => {
					if (pullScroll.page == 1) {
						this.list = [];
					}

					const res = await this.$Api.user.displaceList({
						pageNum: pullScroll.page,
						pageSize: 10,
						// verifyState   0.审核中 1.已同意 2.已拒绝*
						verifyState: this.tabsIndex,
					})

					this.list = this.list.concat(res.rows || []);

					if (res.total == 0) {
						pullScroll.empty()
					}

					if (this.list.length >= res.total) {
						pullScroll.finish();
					} else {
						pullScroll.success();
					}
				}, 500);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}
</style>